package org.dromara.patrol.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.patrol.domain.bo.PatrolReportVerifyBo;
import org.dromara.patrol.domain.vo.PatrolReportVerifyVo;
import org.dromara.patrol.service.IPatrolReportVerifyService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡店管理-巡店报告整改审核
 * 前端访问路由地址为:/patrol/reportVerify
 *
 * @author han
 * @date 2024-03-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/reportVerify")
public class PatrolReportVerifyController extends BaseController {

    private final IPatrolReportVerifyService patrolReportVerifyService;

    /**
     * 查询巡店管理-巡店报告整改审核列表
     */
//    @SaCheckPermission("patrol:reportVerify:list")
    @GetMapping("/list")
    public TableDataInfo<PatrolReportVerifyVo> list(PatrolReportVerifyBo bo, PageQuery pageQuery) {
        return patrolReportVerifyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出巡店管理-巡店报告整改审核列表
     */
    @SaCheckPermission("patrol:reportVerify:export")
    @Log(title = "巡店管理-巡店报告整改审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PatrolReportVerifyBo bo, HttpServletResponse response) {
        List<PatrolReportVerifyVo> list = patrolReportVerifyService.queryList(bo);
        ExcelUtil.exportExcel(list, "巡店管理-巡店报告整改审核", PatrolReportVerifyVo.class, response);
    }

    /**
     * 获取巡店管理-巡店报告整改审核详细信息
     *
     * @param verifyId 主键
     */
//    @SaCheckPermission("patrol:reportVerify:query")
    @GetMapping("/{verifyId}")
    public R<PatrolReportVerifyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long verifyId) {
        return R.ok(patrolReportVerifyService.queryById(verifyId));
    }

    /**
     * 新增巡店管理-巡店报告整改审核
     */
    @SaCheckPermission("patrol:reportVerify:add")
    @Log(title = "巡店管理-巡店报告整改审核", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PatrolReportVerifyBo bo) {
        return toAjax(patrolReportVerifyService.insertByBo(bo));
    }

    /**
     * 修改巡店管理-巡店报告整改审核
     */
    @SaCheckPermission("patrol:reportVerify:edit")
    @Log(title = "巡店管理-巡店报告整改审核", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PatrolReportVerifyBo bo) {
        return toAjax(patrolReportVerifyService.updateByBo(bo));
    }

    /**
     * 删除巡店管理-巡店报告整改审核
     *
     * @param verifyIds 主键串
     */
    @SaCheckPermission("patrol:reportVerify:remove")
    @Log(title = "巡店管理-巡店报告整改审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{verifyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] verifyIds) {
        return toAjax(patrolReportVerifyService.deleteWithValidByIds(List.of(verifyIds), true));
    }
}
